﻿using System;
using System.Configuration;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BLL.Model;
using BLL.RepositoryInterface;
using Infrastructure;

namespace TrainingWorkshopTest
{
    [TestClass]
    public class OrderTest
    {
        [TestMethod]
        public void CanAddNewOrderAndOrderItems()
        {
            Order order = new Order();
            order.OrderId = 0;
            order.CreatedDate = DateTime.Now;
            order.OrderItems = new List<OrderItem>();
            OrderItem orderItemOfProduct1 = new OrderItem();
            orderItemOfProduct1.OrderItemId = 0;
            orderItemOfProduct1.Quantity = 2;
            orderItemOfProduct1.TotalPrice = 9000;
            orderItemOfProduct1.Product = new Product();
            orderItemOfProduct1.Product.ProductId = 1;
            orderItemOfProduct1.Product.ProductName = "DELL LATITUDE 6400";
            orderItemOfProduct1.Product.ProductPrice = 4500;
            order.OrderItems.Add(orderItemOfProduct1);
            OrderItem orderItemOfProduct2 = new OrderItem();
            orderItemOfProduct2.OrderItemId = 0;
            orderItemOfProduct2.Quantity = 2;
            orderItemOfProduct2.TotalPrice = 10000;
            orderItemOfProduct2.Product = new Product();
            orderItemOfProduct2.Product.ProductId = 2;
            orderItemOfProduct2.Product.ProductName = "DELL LATITUDE 6410";
            orderItemOfProduct2.Product.ProductPrice = 5000;
            order.OrderItems.Add(orderItemOfProduct2);
            IOrderRepository repository = RepositoryFactory.GetRepository<IOrderRepository>(GetConnectionString());
            bool isSuccess = repository.SaveOrderAndItems(order);
            Assert.IsTrue(isSuccess);
        }

        private string GetConnectionString()
        {
            return ConfigurationManager.ConnectionStrings["OrderContainer"].ConnectionString;
        }
    }
}
